<html>
<head><meta charset="utf-8"><title>Prorogation of BTreeMap.get · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html">Prorogation of BTreeMap.get</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="201218989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201218989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Avi Dessauer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201218989">(Jun 18 2020 at 01:04)</a>:</h4>
<p>Obviously this is a long way from being able to be marked const.<br>
What is required to at least get propagation working here, so that <code>get</code> is free?</p>
<div class="codehilite"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="kt">usize</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">map</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">map</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="o">*</span><span class="n">map</span><span class="p">.</span><span class="n">get</span><span class="p">(</span><span class="o">&amp;</span><span class="mi">1</span><span class="p">).</span><span class="n">unwrap</span><span class="p">()</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>


<span class="k">fn</span> <span class="nf">map</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">BTreeMap</span><span class="o">&lt;</span><span class="kt">usize</span><span class="p">,</span><span class="w"> </span><span class="kt">usize</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">vec</span><span class="o">!</span><span class="p">[(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">5</span><span class="p">),</span><span class="w"> </span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">7</span><span class="p">)].</span><span class="n">into_iter</span><span class="p">().</span><span class="n">collect</span><span class="p">()</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="201235014"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201235014" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201235014">(Jun 18 2020 at 07:20)</a>:</h4>
<p>you mean you want the body of <code>foo</code> to get optimized to <code>5</code>?</p>



<a name="201265023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201265023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Avi Dessauer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201265023">(Jun 18 2020 at 13:11)</a>:</h4>
<p>Yes, or for it to allocate and drop the btree and return <code>5</code>. I just care about <code>get</code> being replaced with <code>5</code>, not the allocation.</p>



<a name="201266282"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201266282" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201266282">(Jun 18 2020 at 13:21)</a>:</h4>
<p>yea, that's gonna need some serious improvements to either const eval or super aggressive inlining plus a little bit of const prop</p>



<a name="201266413"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201266413" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201266413">(Jun 18 2020 at 13:22)</a>:</h4>
<p>but that's some Haskell level inlining</p>



<a name="201266443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201266443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201266443">(Jun 18 2020 at 13:22)</a>:</h4>
<p>yea, my money's on const eval improvements</p>



<a name="201266546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201266546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201266546">(Jun 18 2020 at 13:23)</a>:</h4>
<p>we need an inlining working group to balance the bets</p>



<a name="201266560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201266560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201266560">(Jun 18 2020 at 13:23)</a>:</h4>
<p>heresy</p>



<a name="201266737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201266737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201266737">(Jun 18 2020 at 13:24)</a>:</h4>
<p>inlining is the pathway to habilities some consider unnatural</p>



<a name="201268345"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201268345" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201268345">(Jun 18 2020 at 13:36)</a>:</h4>
<p>both routes seem implausible to me. what's gonna tell const prop that evaluating so much, at that specific program point, is useful and worth the compile time? what's gonna make the inliner think that inlining everything necessary for simplifying this snippet is a good trade off?</p>



<a name="201271173"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201271173" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201271173">(Jun 18 2020 at 13:58)</a>:</h4>
<p>If you have a <code>const fn</code> call with const arguments, I believe it is reasonable in all cases (and release mode) to replace that call with its result.</p>



<a name="201273355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201273355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Christian Poveda <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201273355">(Jun 18 2020 at 14:13)</a>:</h4>
<p>other than heap allocations what else would be needed?</p>



<a name="201273738"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201273738" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201273738">(Jun 18 2020 at 14:16)</a>:</h4>
<p>impl const trait and then loads of actual impl const traits in libstd</p>



<a name="201472075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201472075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201472075">(Jun 20 2020 at 10:32)</a>:</h4>
<p><span class="user-mention" data-user-id="209924">@Avi Dessauer</span> sounds to me like you are confusing CTFE with constant folding? if all you want is optimizations, you are looking for the latter.</p>



<a name="201472122"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201472122" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201472122">(Jun 20 2020 at 10:34)</a>:</h4>
<p>CTFE (compile-time function evaluation, i.e., all the <code>const stuff</code>) is for using expressions in places where they <em>have to</em> be evaluated at compile-time.</p>



<a name="201472128"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201472128" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201472128">(Jun 20 2020 at 10:34)</a>:</h4>
<p>but the compiler can always <em>try</em> to evaluate things at compiletime as an observation with no observable change in behavior, and in fact it does.</p>



<a name="201472143"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201472143" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201472143">(Jun 20 2020 at 10:35)</a>:</h4>
<p>like if you write a function <code>pub fn foo() { 2+2 }</code> you'll see the assembly just always returns <code>4</code>. and that has nothing to do with CTFE or <code>const</code>.</p>



<a name="201472212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201472212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201472212">(Jun 20 2020 at 10:37)</a>:</h4>
<p>It does somewhat relate to const eval, as const prop can only evaluate <code>const fn</code> function calls, so CTFE needs to support everything to make <code>map</code> and <code>get</code> <code>const fn</code> in order to allow const prop to optimize away the body of <code>foo</code></p>



<a name="201472959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201472959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201472959">(Jun 20 2020 at 11:00)</a>:</h4>
<p>const prop could in principle use the full miri engine</p>



<a name="201473005"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201473005" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201473005">(Jun 20 2020 at 11:00)</a>:</h4>
<p>that hard part about CTFE is not being able to run the code, but being able to statically determine that we can run it</p>



<a name="201473012"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201473012" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201473012">(Jun 20 2020 at 11:00)</a>:</h4>
<p>for const prop we can just run it and if it fails, roll back. so I think the problems are mostly orthogonal.</p>



<a name="201473021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201473021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201473021">(Jun 20 2020 at 11:00)</a>:</h4>
<p>the analysis for whether we <em>want to</em> const prop also seems very different to me from the one whether we are <em>able to</em> CTFE</p>



<a name="201473031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201473031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201473031">(Jun 20 2020 at 11:01)</a>:</h4>
<p>IOW, the fact that const-prop internally uses the miri engine is an implementation detail</p>



<a name="201473292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201473292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201473292">(Jun 20 2020 at 11:09)</a>:</h4>
<p>sure. What I mean is that <em>every</em> <code>const fn</code> call with solely const arguments should be const proppable by just evaluating that function call</p>



<a name="201473547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201473547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201473547">(Jun 20 2020 at 11:17)</a>:</h4>
<p>Although I must point out that "possible" does not necessarily mean "a good idea". With the introduction of control flow, const fns can take arbitrarily long to evaluate, and it's not given that running doing so at compile time pays off (e.g., the call might turn out to be dead, or evaluating it doesn't simplify the IR enough to reduce compile time overall, or miri overhead might be much larger than just compiling it and running the machine code).</p>



<a name="201473593"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201473593" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201473593">(Jun 20 2020 at 11:18)</a>:</h4>
<p>yes that's what I meant above -- whether <em>want to</em>  const prop is a question that is somewhat independent from whether we are <em>able to</em> CTFE.</p>



<a name="201473864"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201473864" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201473864">(Jun 20 2020 at 11:27)</a>:</h4>
<p>sure, but we'll to be able to do it at all before it makes even sense to have the discussion about the feasability.</p>



<a name="201473925"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201473925" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201473925">(Jun 20 2020 at 11:29)</a>:</h4>
<p>I could totally see this as being a clippy lint that tells you "you could put this function call in a constant to make it evaluated at compile-time"</p>



<a name="201490395"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201490395" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Avi Dessauer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201490395">(Jun 20 2020 at 18:23)</a>:</h4>
<p>My question was about both, a guarantee of CTFE is preferable, but I suspect farther out.</p>



<a name="201922516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201922516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Félix Fischer <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201922516">(Jun 25 2020 at 01:07)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124289">Hanna Kruppe</span> <a href="#narrow/stream/146212-t-compiler.2Fconst-eval/topic/Prorogation.20of.20BTreeMap.2Eget/near/201473547">said</a>:</p>
<blockquote>
<p>Although I must point out that "possible" does not necessarily mean "a good idea". With the introduction of control flow, const fns can take arbitrarily long to evaluate, and it's not given that running doing so at compile time pays off (e.g., the call might turn out to be dead, or evaluating it doesn't simplify the IR enough to reduce compile time overall, or miri overhead might be much larger than just compiling it and running the machine code).</p>
</blockquote>
<p>Maybe the solution to this particular problem is to use "anytime optimization", as in, we give that optimizer a certain amount of time that it does not know, to optimize. Its task is thus to deliver progressively optimized versions of the code, and the caller will use the last one that was returned before the time expired - i.e. the "current best one" from the perspective of the optimizer.</p>
<p>This works fairly well for Heuristic Search problems where the optimal route might be arbitrarily costly to compute. You can give "as good as you can" solutions with the allotted time. I think this approach is reasonable for optimizing code, if we ever find ourselves wanting to optimize in a scenario where we don't know the upper bounds of the optimization cost.</p>



<a name="201936669"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/Prorogation%20of%20BTreeMap.get/near/201936669" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/Prorogation.20of.20BTreeMap.2Eget.html#201936669">(Jun 25 2020 at 06:37)</a>:</h4>
<p>that sounds like a discussion for the <a class="stream" data-stream-id="189540" href="/#narrow/stream/189540-t-compiler.2Fwg-mir-opt">#t-compiler/wg-mir-opt</a> channel ;)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>